package com.zx.platform.context;


import com.zx.map.service.AgentInfoService;
import com.zx.map.service.MerchantInfoService;
import com.zx.map.service.model.AgentInfoModel;
import com.zx.map.service.model.MerchantInfoModel;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;

/**
 * @author baojun.liu
 * @version 1.0
 * 根据传过来的ID获取客商或者代理商系统账号
 */
public class GetSysAccounByIdELTag extends TagSupport {

    /**
     * 客商或者代理商ID
     */
    protected String key;
    //执行
    public int doStartTag() throws JspException {
    	String out ="";
    	MerchantInfoService merchantInfoService = (MerchantInfoService) ApplicationContextUtil.getContext().getBean("MerchantInfoService");
    	AgentInfoService agentInfoService = (AgentInfoService) ApplicationContextUtil.getContext().getBean("agentInfoService");
    	 MerchantInfoModel m1=merchantInfoService.getModelByKey(key);
         if(m1==null||m1.getSysAccount()==null||m1.getSysAccount().length()==0){
         	AgentInfoModel  m2=agentInfoService.getModelByKey(key);
         	out=m2.getSysAccount()==null?"":m2.getSysAccount();
         }else{
        	 out=m1.getSysAccount()==null?"":m1.getSysAccount();
         	
         }
         
        try {
            if (null != out) {
                pageContext.getOut().print(out);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return SKIP_BODY;
    }

    //结果
    public int doEndTag() {
        return EVAL_PAGE;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }
}